# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.http import HttpResponse, Http404
from django.views.generic.list_detail import object_list, object_detail
from django.views.generic.create_update import create_object, delete_object, \
    update_object
from google.appengine.ext import db
from mimetypes import guess_type
from mywords.forms import WordForm
from mywords.models import Word
from ragendja.dbutils import get_object_or_404
from ragendja.template import render_to_response

def list_words(request):
    return object_list(request, Word.all(), paginate_by=10)

def show_word(request, key):
    return object_detail(request, Word.all(), key)

def add_word(request):
    return create_object(request, form_class=WordForm,
        post_save_redirect=reverse('mywords.views.show_word',
                                   kwargs=dict(key='%(key)s')))

def edit_word(request, key):
    return update_object(request, object_id=key, form_class=WordForm)

def delete_word(request, key):
    return delete_object(request, Word, object_id=key,
        post_delete_redirect=reverse('mywords.views.list_words'))

